package com.shxzz.easy12306.services.ticket.service.handler.filter.query;

import cn.hutool.core.text.CharSequenceUtil;
import com.shxzz.easy12306.framework.starter.convention.exceptions.ClientException;
import com.shxzz.easy12306.services.ticket.dto.req.TicketPageQueryReqDTO;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
 * 车票查询参数初步验证
 * @author shxzz
 * @create 2024-03-06-14:10
 */
@Component
public class TicketSearchParamBaseVerifyChainFilter implements TicketSearchChainFilter{
    @Override
    public void handler(TicketPageQueryReqDTO requestParam) {
        Date departureDate = requestParam.getDepartureDate();
        if(departureDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().isBefore(LocalDate.now())) {
            throw new ClientException("查询日期不能小于当前日期");
        }
        if(CharSequenceUtil.equals(requestParam.getFromStation(), requestParam.getToStation())) {
            throw new ClientException("出发地不能与目的地相同");
        }
    }

    @Override
    public int getOrder() {
        return 100;
    }
}
